package com.woniuxy.sender;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * @Author: 曾令忠
 * @Description: 向交换机发数据
 * @Date: 2020/7/6 0006-上午 10:42
 */
@Component
public class ProductSender {
    @Autowired
    public RabbitTemplate rabbitTemplate;

    private static Executor executor = Executors.newFixedThreadPool(5);

    public void send(int pid){
        //固定线程池实现限流限速操作
        executor.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println("用户模块向商户模块发送请求");
                rabbitTemplate.convertAndSend("rpc_exchange_a","",pid);
            }
        });
    }
}
